#include<bits/stdc++.h> 
#define  int long long 
#define endl '\n'
using namespace std;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 2e18;
int n, m, ans=0;

map<int,int> mp;

bool querry(map<int, int>& mp, int m) {
    for (int i = 1; i <= m; i++) {
        if (!mp.count(i)) return false;
    }
    return true;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    map<int, int> mp;
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    
    
    if (!querry(mp, m)) {
        cout << 0 << endl;
        return;
    }
    
    int ans = 1;
    for (int i = n-1; i >= 0; i--) {
        mp[a[i]]--;
        if (mp[a[i]] == 0) {
            mp.erase(a[i]);
        }
        if (querry(mp, m)) {
            ans++;
        } else {
            break;
        }
    }
    cout << ans << endl;
}
signed main(){
	int t=1;
	while(t--){
		solve();
	}
	return 0;
} 

